package com.wuseguang.springcloud.dao.jdbc;

import com.wuseguang.springcloud.JdbcTemplate.BaseTemplate;
import com.wuseguang.springcloud.entity.Holiday;
import com.wuseguang.springcloud.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class BanCardsJdbc extends BaseTemplate {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public Map<String, Object> queryMap1(String sql, Object... arg) {
        return dao.query(sql, arg, rs -> {
            Map<String, Object> map = new HashMap<>();
            //monday,tuesday,wednesday,thursday,friday,saturday,sunday
            while (rs.next()) {
                String monday = rs.getString("monday");
                String tuesday = rs.getString("tuesday");
                String wednesday = rs.getString("wednesday");
                String thursday = rs.getString("thursday");
                String friday = rs.getString("friday");
                String saturday = rs.getString("saturday");
                String sunday = rs.getString("sunday");
                if ((monday == null || "".equals(monday)) && (tuesday == null || "".equals(tuesday)) && (wednesday == null || "".equals(wednesday)) && (thursday == null || "".equals(thursday)) && (friday == null || "".equals(friday)) && (saturday == null || "".equals(saturday)) && (sunday == null || "".equals(sunday))) {
                    return map;
                }
                map.put("monday", monday);
                map.put("tuesday", tuesday);
                map.put("wednesday", wednesday);
                map.put("thursday", thursday);
                map.put("friday", friday);
                map.put("saturday", saturday);
                map.put("sunday", sunday);
            }
            return map;
        });
    }

    public Map<Integer, Object> findAttendClassTime(Object school_id) {
        //查询上课时间SQL
        String sql = "select current_section,start_time,end_time from attend_class_time where school_id = ?";

        return dao.query(sql, new Object[]{school_id}, rs -> {
            Map<Integer, Object> map = new HashMap<Integer, Object>();
            while (rs.next()) {
                map.put(rs.getInt("current_section"), rs.getString("start_time") + "-" + rs.getString("end_time"));
            }
            return map;
        });
    }
}
